{% if include.selector %}
  {% assign selector = include.selector %}
{% endif %}

{% if include.seed %}
  {% assign seed = include.seed %}
{% endif %}

<script src="/assets/js/trianglify.min.js"></script>
<script>
  function setRandomBgImage(selector, seed, zoom) {
    var element = document.querySelector(selector);
    if (!element) return;
    var pattern = Trianglify({
      width: screen.width * zoom,
      height: element.offsetHeight * zoom,
      seed: seed
    });

    var image = document.createElement("div");
    image.style.backgroundImage = "url(" + pattern.png() + ")";
    element.appendChild(image);
  }

  setRandomBgImage('{{ selector }}', '{{ seed }}', {{ zoom | default: 1}});
</script>
